<?php

namespace App\Http\Controllers\Admin\User;

use Illuminate\Http\Request;
use App\Http\Controllers\Admin\HomeController as Controller;
use App\Repository\UserRepository;
class HomeController extends Controller
{
    protected $user;

    public function __construct(UserRepository $user)
    {
        $this->user = $user;
    }

    public function index()
    {
        $users = $this->user->getBindUsers();

        return view('admin.user.information', ['users' => $users]);
    }


    public function updateUser($id, Request $request)
    {
        $this->validate($request, [
            'shortphone' => ['regex:/^[3-8][0-9]{2,5}$/'],
            'cellphone' => ['regex:/^(13\d|14[57]|15[^4,\D]|17[678]|18\d)\d{8}$|^170[059]\d{7}$/'],
        ],[
            'cellphone.regex' => '长号格式不正确',
            'shortphone.regex' => '短号格式不正确',
        ]);

        $this->user->update($id, [
            'name' => $request->input('name'),
            'cellphone' => $request->input('cellphone'),
            'short_phone' => $request->input('shortphone'),
            'dormitory_address' => $request->input('address'),
        ]);

        return $this->user->getUser($id);
    }
}
